#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

int main(int argc, int *argv[])
{
    int fd;
    unsigned int offset;
    char readbuff1[32];
    char readbuff2[32];
    fd = open("/dev/test_drive", O_RDWR, 666);
    if (fd < 0)
        perror("open faile!\n");

    write(fd, "i am lyh,HiHiHi\n", 17);
    offset = lseek(fd, 0, SEEK_CUR); // 读取当前位置
    printf("offset is %d\n", offset);

    offset = lseek(fd, 0, SEEK_SET); // 设为开头
    printf("offset is %d\n", offset);
    read(fd, readbuff1, 32);

    offset = lseek(fd, 0, SEEK_CUR); // 读取当前位置
    printf("offset is %d\n", offset);

    offset = lseek(fd, -5, SEEK_CUR); // 往前nuo一位
    printf("offset is %d\n", offset);

    write(fd, "LLLLinux", 9);
    offset = lseek(fd, 0, SEEK_CUR); // 读取当前位置
    printf("offset is %d\n", offset);

    offset = lseek(fd, 0, SEEK_SET); // 设为开头
    read(fd, readbuff2, 32);
    printf("buff2 is %s\n", readbuff2);
    close(fd);
    return 0;
}